
package com.idealighter.game.games.errentexaspoker.handler;

import com.idealighter.game.core.annotation.ResMsgHandler;
import com.idealighter.game.gamehall.dto.SeatInfo;
import com.idealighter.game.games.errentexaspoker.ErrenTexaspokerPlayer;
import com.idealighter.game.games.errentexaspoker.message.ResNextSeatMsg;
import com.idealighter.game.message.core.ResMessage;
import com.idealighter.game.robot.core.Player;
import com.idealighter.game.robot.handler.ResMessageHandler;
import com.idealighter.utils.code.RandCodeUtil;

import java.util.concurrent.TimeUnit;


@ResMsgHandler(515220)
public class ResNextSeatHandler implements ResMessageHandler {

  @Override
  public void action(Player player, ResMessage message) {
    ResNextSeatMsg msg = (ResNextSeatMsg) message;
    ErrenTexaspokerPlayer texaspokerPlayer = (ErrenTexaspokerPlayer) player;
    SeatInfo seatInfo = texaspokerPlayer.seat(player.playerId);
    if (seatInfo != null && seatInfo.getOrder() == msg.getOrder()) {
      int time = RandCodeUtil.random(texaspokerPlayer.domain.getTimeMin(),
          texaspokerPlayer.domain.getTimeMax());
      if (time == 0) {
        time = RandCodeUtil.random(3, 6);
      }
      player.schedule(() -> texaspokerPlayer.betDesision(msg.getCurMaxBet(), msg.getRaisetBet()),
          time, TimeUnit.SECONDS);
    }
  }
}
